package com.authine.cloudpivot.web.api.controller;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.web.api.bean.RoleAndUser;
import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.exception.PortalException;
import com.authine.cloudpivot.web.api.service.ProjectTeamService;
import com.authine.cloudpivot.web.api.service.QuestionnaireService;
import com.authine.cloudpivot.web.api.view.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(description = "外企德科相关接口", tags = "问卷调查接口")
@RestController
@RequestMapping("/api/questionnaire")
@Slf4j
@Validated
public class QuestionnaireController extends BaseController {

    @Autowired
    private QuestionnaireService questionnaireService;

    /**
     * @Description : 获取项目所有问卷模型
     * @param ： projectId
     * @author : Liun
     * @date : 2020/6/22
     */
    @ApiOperation(value = "获取项目问卷列表" )
    @GetMapping("/getAppFunctionNames")
    @ResponseBody
    public ResponseResult<?> getAppFunctionNames(String projectNo){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            List<String> appFunctionNamesList= questionnaireService.getAppFunctionNames(projectNo);
            if(ObjectUtil.isNotNull(appFunctionNamesList)){
                JSONArray appFunctionName = JSONArray.fromObject(appFunctionNamesList);
                json.put("appFunctionNameList",appFunctionName);
            }
            json.put("message","获取项目问卷成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "获取项目问卷失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }



    /**
     * @Description : 推送调查问卷消息通知
     * @param ： projectId
     * @param ： Questionnaire
     * @author : Liun
     * @date : 2020/6/22
     */
    @ApiOperation(value = "推送调查问卷消息通知" )
    @GetMapping("/remindQuestionnaire")
    @ResponseBody
    public ResponseResult<?> remindQuestionnaire(String objectId,String questionnaire,String storeRotation,String subjectNames){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            questionnaireService.remindQuestionnaire(objectId,questionnaire,storeRotation,subjectNames);
            json.put("message","推送调查问卷消息通知成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "推送调查问卷消息通知失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }









}
